<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<div class="sidebar">
        <div class="sidebar-dropdown"><a href="#">导航</a></div>

        <!--- Sidebar navigation -->
        <!-- If the main navigation has sub navigation, then add the class "has_sub" to "li" of main navigation. -->
       
	<ul id="nav" style="">
        <!-- 菜单树 -->
          
     </ul>
</div>
<script type="text/javascript">
		$(function(){
			$.ajax({
				url : "${pageContext.request.contextPath}/menu/selectMenu.action",
				type : "POST",
				dataType : "json", 
				data : {},
				success : function(result, start, resp) {
					    var	mstr='';
					    if(result!=null){
							mstr='<li><a href="#" class="open"><i class="icon-home"></i>'+result.name+'</a></li>';					    	
							if(result.list!=null){
					    		for(var i=0;i<result.list.length;i++){
					    			var pval=result.list[i];
							    	mstr+='<li class="has_sub"><a href="#"><i class="icon-list-alt"></i>'+result.list[i].name+'<span class="pull-right"><i class="icon-chevron-right"></i></span></a>';
							    		mstr=mstr+"<ul>";
							    		var mstr2='';
							    		for(var j=0;j<pval.list.length;j++){
							    			mstr2+='<li value="'+pval.list[j].uuid+'"><a href="${pageContext.request.contextPath}/'+pval.list[j].url+'" >'+pval.list[j].name+'</a></li>';
							    		}
							    		mstr=mstr+mstr2+"</ul>";
							    	
							    	mstr=mstr+"</li>";
							    } 
					    	}
					    } 
						$("#nav").append(mstr); 
						
						

					$(window).resize(function()
						  {
						    if($(window).width() >= 765){
						      $(".sidebar #nav").slideDown(350);
						    }
						    else{
						      $(".sidebar #nav").slideUp(350); 
						    }
					});

					$("#nav > li > a").on('click',function(e){
						      if($(this).parent().hasClass("has_sub")) {
						        e.preventDefault();
						      }   

						      if(!$(this).hasClass("subdrop")) {
						        // hide any open menus and remove all other classes
						        $("#nav li ul").slideUp(350);
						        $("#nav li a").removeClass("subdrop");
						        
						        // open our new menu and add the open class
						        $(this).next("ul").slideDown(350);
						        $(this).addClass("subdrop");
						      }
						      
						      else if($(this).hasClass("subdrop")) {
						        $(this).removeClass("subdrop");
						        $(this).next("ul").slideUp(350);
						      } 
						      
					});
						  
						  
					$(".sidebar-dropdown a").on('click',function(e){
						      e.preventDefault();
						      if(!$(this).hasClass("open")) {
						        // hide any open menus and remove all other classes
						        $(".sidebar #nav").slideUp(350);
						        $(".sidebar-dropdown a").removeClass("open");
						        
						        // open our new menu and add the open class
						        $(".sidebar #nav").slideDown(350);
						        $(this).addClass("open");
						      }
						      
						      else if($(this).hasClass("open")) {
						        $(this).removeClass("open");
						        $(".sidebar #nav").slideUp(350);
						      }
					});
					
					$(window).resize(function()
						  {
						    if($(window).width() >= 765){
						      $(".sidebar #nav").slideDown(350);
						    }
						    else{
						      $(".sidebar #nav").slideUp(350); 
						    }
					});

				
				} 
			});
		});
	</script>
